home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Oberon / source / amiga / Commodities.mod < prev    next >
Text File  |  1995-06-29  |  12KB  |  431 lines

  1. (***************************************************************************
  2.  
  3.      $RCSfile: Commodities.mod $
  4.   Description: Interface to commodities.library
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 3.8 $
  8.       $Author: fjc $
  9.         $Date: 1995/06/04 23:13:14 $
  10.  
  11.   Includes Release 40.15
  12.  
  13.   (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  14.       All Rights Reserved
  15.  
  16.   Oberon-A interface Copyright © 1994-1995, Frank Copeland.
  17.   This file is part of the Oberon-A Interface.
  18.   See Oberon-A.doc for conditions of use and distribution.
  19.  
  20. ***************************************************************************)
  21.  
  22. <* STANDARD- *>
  23.  
  24. MODULE [2] Commodities;
  25.  
  26. IMPORT
  27.   SYS := SYSTEM, Kernel, e := Exec, Ie := InputEvent, Km := KeyMap,
  28.   s := Sets;
  29.  
  30. (**-- Pointer declarations ---------------------------------------------*)
  31.  
  32. TYPE
  33.  
  34.   NewBrokerPtr *      = POINTER TO NewBroker;
  35.   InputXpressionPtr * = POINTER TO InputXpression;
  36.   IXPtr *             = POINTER TO IX;
  37.   CxObjPtr *          = POINTER TO CxObj;
  38.   CxMsgPtr *          = POINTER TO CxMsg;
  39.  
  40. (*
  41. **      $VER: commodities.h 38.4 (24.2.93)
  42. **
  43. **      Commodities definitions.
  44. *)
  45.  
  46. (*****************************************************************************)
  47.  
  48. CONST
  49.  
  50. (* Sizes for various buffers *)
  51.   nameLen * = 24;
  52.   titleLen * = 40;
  53.   descrLen * = 40;
  54.  
  55. TYPE
  56.  
  57.   NameStr * = ARRAY nameLen OF CHAR;
  58.   TitleStr * = ARRAY titleLen OF CHAR;
  59.   DescrStr * = ARRAY descrLen OF CHAR;
  60.  
  61.   NewBroker * = RECORD
  62.     version * :  SHORTINT;        (* Must be set to NB_VERSION *)
  63.     name *    :  POINTER TO NameStr;
  64.     title *   :  POINTER TO TitleStr;
  65.     descr *   :  POINTER TO DescrStr;
  66.     unique *  :  s.SET16;
  67.     flags *   :  s.SET16;
  68.     pri *     :  SHORTINT;
  69.     port *    :  e.MsgPortPtr;
  70.     reservedChannel * :  INTEGER;
  71.   END;
  72.  
  73. CONST
  74.  
  75. (* constant for NewBroker.version *)
  76.   nbVersion * = 5;          (* Version of NewBroker structure *)
  77.  
  78. (* Flags for NewBroker.unique *)
  79.   duplicate * = 0;
  80.   unique * = 1;             (* will not allow duplicates           *)
  81.   notify * = 2;             (* sends cxmUnique to existing broker *)
  82.  
  83. (* Flags for NewBroker.flags *)
  84.   showHide * = 4;
  85.  
  86.  
  87. (*****************************************************************************)
  88.  
  89. TYPE
  90.  
  91. (* Fake data types for system private objects *)
  92.   CxObj = RECORD END;
  93.   CxMsg = RECORD END;
  94.  
  95. (* Pointer to a function returning a LONG *)
  96.   PFL = PROCEDURE () : LONGINT;
  97.  
  98.  
  99. (*****************************************************************************)
  100.  
  101. CONST
  102.  
  103. (* Commodities object types *)
  104.   invalid *    = 0;  (* not a valid object (probably null) *)
  105.   filter *     = 1;  (* input event messages only          *)
  106.   typeFilter * = 2;  (* obsolete, do not use               *)
  107.   send *       = 3;  (* sends a message                    *)
  108.   signal *     = 4;  (* sends a signal                     *)
  109.   translate *  = 5;  (* translates input event into chain  *)
  110.   broker *     = 6;  (* application representative         *)
  111.   debug *      = 7;  (* dumps info to serial port          *)
  112.   custom *     = 8;  (* application provides function      *)
  113.   zero *       = 9;  (* system terminator node             *)
  114.  
  115.  
  116. (*****************************************************************************)
  117.  
  118. CONST
  119.  
  120. (* Commodities message types *)
  121.   cxmIEvent * = 32;
  122.   cxmCommand * = 64;
  123.  
  124. (* Only mIEvent messages are passed through the input network. Other types
  125.  * of messages are sent to an optional port in your broker. This means that
  126.  * you must test the message type in your message handling, if input messages
  127.  * and command messages come to the same port.
  128.  *
  129.  * cxmIEvent:  Messages of this type rattle around the Commodities input
  130.  *             network. They are sent to you by a Sender object, and passed
  131.  *             to you as a synchronous function call by a Custom object.
  132.  *
  133.  *             The message port or function entry point is stored in the
  134.  *             object, and the ID field of the message will be set to what
  135.  *             you arrange issuing object.
  136.  *
  137.  *             The data section of the message will point to the input event
  138.  *             triggering the message.
  139.  *
  140.  * cxmCommand: These messages are sent to a port attached to your Broker.
  141.  *             They are sent to you when the controller program wants your
  142.  *             program to do something. The ID value identifies the command.
  143.  *)
  144.  
  145. CONST
  146.  
  147. (* ID values associated with a message of type mCommand *)
  148.   cmdDisable * = 15;        (* please disable yourself         *)
  149.   cmdEnable * = 17;         (* please enable yourself  *)
  150.   cmdAppear * = 19;         (* open your window, if you can    *)
  151.   cmdDisappear * = 21;      (* go dormant                      *)
  152.   cmdKill * = 23;           (* go away for good                *)
  153.   cmdListChg * = 27;        (* Someone changed the broker list *)
  154.   cmdUnique * = 25;         (* someone tried to create a broker
  155.                              * with your name. Suggest you appear.
  156.                              *)
  157.  
  158.  
  159. (*****************************************************************************)
  160.  
  161. TYPE
  162.  
  163.   InputXpression * = RECORD
  164.     version *   :  SHORTINT; (* must be set to ixVersion *)
  165.     class *     :  SHORTINT; (* class must match exactly  *)
  166.  
  167.     code *      :  s.SET16;  (* Bits that we want *)
  168.     codeMask *  :  INTEGER;  (* Set bits here to indicate which bits in code
  169.                               * are don't care bits.
  170.                               *)
  171.     qualifier * :  s.SET16;  (* Bits that we want *)
  172.     qualMask *  :  s.SET16;  (* Set bits here to indicate which bits in
  173.                               * qualifier are don't care bits
  174.                               *)
  175.     qualSame *  :  s.SET16;  (* synonyms in qualifier *)
  176.   END;
  177.  
  178.   IX * = InputXpression;
  179.  
  180. CONST
  181.  
  182. (* constant for InputXpression.version *)
  183.   ixVersion * = 2;
  184.  
  185. (* constants for InputXpression.qualSame *)
  186.   ixSymShift * = 0;     (* left- and right- shift are equivalent     *)
  187.   ixSymCaps * = 1;      (* either shift or caps lock are equivalent  *)
  188.   ixSymAlt * = 2;       (* left- and right- alt are equivalent       *)
  189.  
  190.   ixSymShiftMask * = {Ie.lShift, Ie.rShift};
  191.   ixSymCapsMask * = ixSymShiftMask + {Ie.capsLock};
  192.   ixSymAltMask * = {Ie.lAlt, Ie.rAlt};
  193.  
  194. (* constant for InputXpression.qualMask *)
  195.   ixNormalQuals * = -{Ie.relativeMouse};     (* avoid RELATIVEMOUSE *)
  196.  
  197.  
  198. (*****************************************************************************)
  199.  
  200. CONST
  201.  
  202. (* Error returns from CxBroker() *)
  203.   errOk * = 0;          (* No error                               *)
  204.   errSysErr * = 1;      (* System error, no memory, etc           *)
  205.   errDup * = 2;         (* uniqueness violation                   *)
  206.   errVersion * = 3;     (* didn't understand NewBroker.nb_Version *)
  207.  
  208.  
  209. (*****************************************************************************)
  210.  
  211. CONST
  212.  
  213. (* Return values from CxObjError() *)
  214.   coErrIsNull * = 0;           (* you called CxObjError(NULL)        *)
  215.   coErrNullAttach * = 1;       (* someone attached NULL to my list   *)
  216.   coErrBadFilter * = 2;        (* a bad filter description was given *)
  217.   coErrBadType * = 3;          (* unmatched type-specific operation  *)
  218.  
  219.  
  220. (*****************************************************************************)
  221.  
  222. TYPE
  223.   LONGBOOL * = e.LONGBOOL;
  224.  
  225. CONST
  226.   LTRUE * = e.LTRUE;
  227.   LFALSE * = e.LFALSE;
  228.  
  229.  
  230. (**-- Library Base variable --------------------------------------------*)
  231.  
  232. CONST
  233.  
  234.   commoditiesName * = "commodities.library";
  235.  
  236. VAR
  237.  
  238.   base * : e.LibraryPtr;
  239.  
  240.  
  241. (**-- Library Functions ------------------------------------------------*)
  242.  
  243. (*
  244. **      $VER: commodities_protos.h 38.4 (27.2.92)
  245. *)
  246.  
  247. TYPE
  248.   CustomProcType * = PROCEDURE ( obj : CxObjPtr; msg : CxMsgPtr );
  249.  
  250. (* --- functions in V36 or higher (distributed as Release 2.0) ---*)
  251.  
  252. (*  OBJECT UTILITIES *)
  253.  
  254. PROCEDURE CreateCxObj* [base,-30]
  255.   ( type [0] : e.ULONG;
  256.     arg1 [8] : SYS.LONGWORD;
  257.     arg2 [9] : SYS.LONGWORD )
  258.   : CxObjPtr;
  259. PROCEDURE CxBroker* [base,-36]
  260.   ( VAR nb    [8] : NewBroker;
  261.     VAR error [0] : LONGINT )
  262.   : CxObjPtr;
  263. PROCEDURE ActivateCxObj* [base,-42]
  264.   ( co   [8] : CxObjPtr;
  265.     true [0] : LONGBOOL )
  266.   : LONGBOOL;
  267. PROCEDURE DeleteCxObj* [base,-48]
  268.   ( co [8] : CxObjPtr );
  269. PROCEDURE DeleteCxObjAll* [base,-54]
  270.   ( co [8] : CxObjPtr );
  271. PROCEDURE CxObjType* [base,-60]
  272.   ( co [8] : CxObjPtr )
  273.   : e.ULONG;
  274. PROCEDURE CxObjError* [base,-66]
  275.   ( co [8] : CxObjPtr )
  276.   : s.SET32;
  277. PROCEDURE ClearCxObjError* [base,-72]
  278.   ( co [8] : CxObjPtr );
  279. PROCEDURE SetCxObjPri* [base,-78]
  280.   ( co  [8] : CxObjPtr;
  281.     pri [0] : LONGINT )
  282.   : LONGINT;
  283.  
  284. (*  OBJECT ATTACHMENT *)
  285.  
  286. PROCEDURE AttachCxObj* [base,-84]
  287.   ( headObj [8] : CxObjPtr;
  288.     co      [9] : CxObjPtr );
  289. PROCEDURE EnqueueCxObj* [base,-90]
  290.   ( headObj [8] : CxObjPtr;
  291.     co      [9] : CxObjPtr );
  292. PROCEDURE InsertCxObj* [base,-96]
  293.   ( headObj [8] : CxObjPtr;
  294.     co      [9] : CxObjPtr;
  295.     pred   [10] : CxObjPtr );
  296. PROCEDURE RemoveCxObj* [base,-102]
  297.   ( co [8] : CxObjPtr );
  298.  
  299. (*  TYPE SPECIFIC *)
  300.  
  301. PROCEDURE SetTranslate* [base,-114]
  302.   ( translator [8] : CxObjPtr;
  303.     VAR events [9] : Ie.InputEvent );
  304. PROCEDURE SetFilter* [base,-120]
  305.   ( filter [8] : CxObjPtr;
  306.     text   [9] : ARRAY OF CHAR );
  307. PROCEDURE SetFilterIX* [base,-126]
  308.   ( filter [8] : CxObjPtr;
  309.     VAR ix [9] : IX );
  310. PROCEDURE ParseIX* [base,-132]
  311.   ( description [8] : ARRAY OF CHAR;
  312.     VAR ix      [9] : IX )
  313.   : LONGINT;
  314.  
  315. (*  COMMON MESSAGE *)
  316.  
  317. PROCEDURE CxMsgType* [base,-138]
  318.   ( cxm [8] : CxMsgPtr )
  319.   : s.SET32;
  320. PROCEDURE CxMsgData* [base,-144]
  321.   ( cxm [8] : CxMsgPtr )
  322.   : e.APTR;
  323. PROCEDURE CxMsgID* [base,-150]
  324.   ( cxm [8] : CxMsgPtr )
  325.   : LONGINT;
  326.  
  327. (*  MESSAGE ROUTING *)
  328.  
  329. PROCEDURE DivertCxMsg* [base,-156]
  330.   ( cxm     [8] : CxMsgPtr;
  331.     headobj [9] : CxObjPtr;
  332.     ret    [10] : CxObjPtr );
  333. PROCEDURE RouteCxMsg* [base,-162]
  334.   ( cxm [8] : CxMsgPtr;
  335.     co  [9] : CxObjPtr );
  336. PROCEDURE DisposeCxMsg* [base,-168]
  337.   ( cxm [8] : CxMsgPtr );
  338.  
  339. (*  INPUT EVENT HANDLING *)
  340.  
  341. PROCEDURE InvertKeyMap* [base,-174]
  342.   ( ansicode [0] : e.ULONG;
  343.     event    [8] : Ie.InputEventDummyPtr;
  344.     km       [9] : Km.KeyMapPtr )
  345.   : BOOLEAN;
  346. PROCEDURE AddIEvents* [base,-180]
  347.   ( events [8] : Ie.InputEventDummyPtr );
  348.  
  349. (*--- functions in V38 or higher (Release 2.1) ---*)
  350.  
  351. (*  MORE INPUT EVENT HANDLING *)
  352.  
  353. PROCEDURE MatchIX* [base,-204]
  354.   ( event [8] : Ie.InputEventDummyPtr;
  355.     ix    [9] : IXPtr )
  356.   : BOOLEAN;
  357.  
  358. (**-- C Macros defined as procedures -----------------------------------*)
  359.  
  360. <*$LongVars+*>
  361.  
  362. (*************************
  363.  * object creation macros
  364.  *************************)
  365.  
  366. (**-----------------------------------*)
  367. PROCEDURE [0] CxFilter * (d : e.APTR)
  368.   : CxObjPtr;
  369. BEGIN (* CxFilter *)
  370.   RETURN CreateCxObj (filter, d, NIL)
  371. END CxFilter;
  372.  
  373. (**-----------------------------------*)
  374. PROCEDURE [0] CxTypeFilter * (type : e.APTR)
  375.   : CxObjPtr;
  376. BEGIN (* CxTypeFilter *)
  377.   RETURN CreateCxObj (typeFilter, type, NIL)
  378. END CxTypeFilter;
  379.  
  380. (**-----------------------------------*)
  381. PROCEDURE [0] CxSender * (port : e.MsgPortPtr; id : e.APTR)
  382.   : CxObjPtr;
  383. BEGIN (* CxSender *)
  384.   RETURN CreateCxObj (send, port, id)
  385. END CxSender;
  386.  
  387. (**-----------------------------------*)
  388. PROCEDURE [0] CxSignal * (task : e.TaskPtr; sig : INTEGER)
  389.   : CxObjPtr;
  390. BEGIN (* CxSignal *)
  391.   RETURN CreateCxObj (signal, task, sig)
  392. END CxSignal;
  393.  
  394. (**-----------------------------------*)
  395. PROCEDURE [0] CxTranslate * (ie : Ie.InputEventDummyPtr)
  396.   : CxObjPtr;
  397. BEGIN (* CxTranslate *)
  398.   RETURN CreateCxObj (translate, ie, NIL)
  399. END CxTranslate;
  400.  
  401. (**-----------------------------------*)
  402. PROCEDURE [0] CxDebug * (id : e.APTR)
  403.   : CxObjPtr;
  404. BEGIN (* CxDebug *)
  405.   RETURN CreateCxObj (debug, id, NIL)
  406. END CxDebug;
  407.  
  408. (**-----------------------------------*)
  409. PROCEDURE [0] CxCustom * (action : CustomProcType; id : e.APTR)
  410.   : CxObjPtr;
  411. BEGIN (* CxCustom *)
  412.   RETURN CreateCxObj (custom, action, id)
  413. END CxCustom;
  414.  
  415.  
  416. (**-- Library Base variable --------------------------------------------*)
  417.  
  418. <*$LongVars-*>
  419.  
  420. (**-----------------------------------*)
  421. PROCEDURE* [0] CloseLib (VAR rc : LONGINT);
  422.  
  423. BEGIN (* CloseLib *)
  424.   IF base # NIL THEN e.CloseLibrary (base) END;
  425. END CloseLib;
  426.  
  427. BEGIN
  428.   base := e.OpenLibrary (commoditiesName, e.libraryMinimum);
  429.   IF base # NIL THEN Kernel.SetCleanup (CloseLib) END
  430. END Commodities.
  431.